<?php
class Action extends admin_abs
{
	function index()
	{
	
		$type = _GET('type', 0);
		$open_id = _GET('open_id', 1);
		
		$sql = "WHERE type='$type' ";
		if	($open_id) { //1
			$sql .= "AND use_time > 0";
		} else { //0
			$sql .= "AND use_time = 0";
		}
		$data = _model('sn')->getList($sql, new Pager(50));
		Smarty3::instance()->assign($data);
		Smarty3::instance()->assign('type', $type);
		Smarty3::instance()->assign('open_id', $open_id);

		Smarty3::instance()->display('snabout_list.html');
	}
	
	function create()
	{
		for ($i=0;$i<50;$i++) {
		$num = gen_sn();
		$type = _GET('type', 0);
		if (!$data = _model('sn')->getList(" WHERE sn_key='$num' ")) {
			_model('sn')->create(array('sn_key'=>$num, 'type'=>$type, 'add_time'=>time()));
		}
	}
		redirect();
	}
}


function gen_sn() {
    $f = create_function('', "return strtoupper(substr(str_shuffle(implode(array_merge(range(0,9),range('a','z')))), 0, 4));");
    return $f().'-'.$f();
}
?>